var needRecProjectStore = null;
var needRecPremisesStore = null;
var needRecBuildingStore = null;
var needRecUnitStore = null;
var needRecRoomStore = null;
var gridStoreg = null;

Ext.define('component.marketing.needReceive', {
	extend : 'Ext.form.Panel',
	initComponent:function(){
		
		//项目
		needRecProjectStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "projectName"],
	        proxy:{
	            type:'ajax',
	            url:contextPath+'/estate/project/findProjectList?needAuth=T&resourcesCode=menu_0003_0001',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              }
	        } ,
	        autoLoad: false
		});
		needRecProjectStore.load({
			callback:function(records, options, success){
				var count = needRecProjectStore.getCount();
				if(count>0){
					var id = needRecProjectStore.getAt(0).get("id");
					Ext.getCmp('needRecProjectStore').setValue(id)
				}
				if(Ext.Array.contains(idata,"fin:list:all")){
					var data = {"projectName": "全部", "id": '-1'};
					var rs = Ext.create(data);
					needRecProjectStore.insert(count+1, rs);
				}
			}
		});
		//组团
		needRecPremisesStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "groupName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectPremises/findPremisesList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		
		needRecPremisesStore.on("beforeload", function(){
			needRecPremisesStore.removeAll();
			needRecBuildingStore.removeAll();
			needRecUnitStore.removeAll();
			needRecRoomStore.removeAll();
			Ext.getCmp("needRecPremisesStore").setValue("");
			Ext.getCmp("needRecBuildingStore").setValue("")
			Ext.getCmp("needRecUnitStore").setValue("")
			Ext.getCmp("needRecRoomStore").setValue("")
			var projectId = Ext.getCmp("needRecProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			needRecPremisesStore.proxy.extraParams.projectId = projectId;
		});
		//楼栋
		needRecBuildingStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "buildingName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectBuilding/findBuildingList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		needRecBuildingStore.on("beforeload", function(){
			needRecBuildingStore.removeAll();
			needRecUnitStore.removeAll();
			needRecRoomStore.removeAll();
			Ext.getCmp("needRecBuildingStore").setValue("")
			Ext.getCmp("needRecUnitStore").setValue("")
			Ext.getCmp("needRecRoomStore").setValue("")
			var projectId = Ext.getCmp("needRecProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			var premisesId = Ext.getCmp("needRecPremisesStore").getValue();
			needRecBuildingStore.proxy.extraParams.projectId = projectId;
			needRecBuildingStore.proxy.extraParams.premisesId = premisesId;
		});
		//单元
		needRecUnitStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "unitName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectUnit/findUnitList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		needRecUnitStore.on("beforeload", function(){
			needRecUnitStore.removeAll();
			needRecRoomStore.removeAll();
			Ext.getCmp("needRecUnitStore").setValue("")
			Ext.getCmp("needRecRoomStore").setValue("")
			var projectId = Ext.getCmp("needRecProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			var premisesId = Ext.getCmp("needRecPremisesStore").getValue();
			var buildingId = Ext.getCmp("needRecBuildingStore").getValue();
			needRecUnitStore.proxy.extraParams.projectId = projectId;
			needRecUnitStore.proxy.extraParams.premisesId = premisesId;
			needRecUnitStore.proxy.extraParams.buildingId = buildingId;
		});
		//房间
		needRecRoomStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "roomName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectRoom/findRoomList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		needRecRoomStore.on("beforeload", function(){
			needRecRoomStore.removeAll();
			Ext.getCmp("needRecRoomStore").setValue("")
			var projectId = Ext.getCmp("needRecProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			var premisesId = Ext.getCmp("needRecPremisesStore").getValue();
			var buildingId = Ext.getCmp("needRecBuildingStore").getValue();
			var unitId = Ext.getCmp("needRecUnitStore").getValue();
			needRecRoomStore.proxy.extraParams.projectId = projectId;
			needRecRoomStore.proxy.extraParams.premisesId = premisesId;
			needRecRoomStore.proxy.extraParams.buildingId = buildingId;
			needRecRoomStore.proxy.extraParams.unitId = unitId;
		});
		
		//房款类型
	    var type = [
	         {"value":"","text":"请选择"},
	         {"value":"1","text":"认筹金"},
	         {"value":"3","text":"认购金"},
	         {"value":"5","text":"一次性全款"},
	         {"value":"6","text":"商业贷款-首付款"},
	         {"value":"7","text":"商业贷款-按揭款"},
	         {"value":"10","text":"公积金-首付款"},
	         {"value":"11","text":"公积金-按揭款"},
	         {"value":"12","text":"分期-一期款"},
	         {"value":"13","text":"分期-二期款"},
	         {"value":"14","text":"分期-三期款"},
	         {"value":"15","text":"分期-四期款"},
	         {"value":"16","text":"分期-五期款"},
	         {"value":"17","text":"组合贷款-首付款"},
	         {"value":"18","text":"组合贷款-银行按揭"},
	         {"value":"19","text":"组合贷款-公积金按揭"},
	         {"value":"20","text":"签约金"},
	         {"value":"23","text":"补差款"},
	         {"value":"26","text":"一次性全款(首付分期)"},
	         {"value":"27","text":"商业贷款首付款(首付分期)"},
	         {"value":"28","text":"商业贷款按揭款(首付分期)"},
	         {"value":"29","text":"分期一期款(首付分期)"},
	         {"value":"30","text":"分期二期款(首付分期)"},
	         {"value":"31","text":"分期三期款(首付分期)"},
	         {"value":"32","text":"分期四期款(首付分期)"},
	         {"value":"33","text":"分期五期款(首付分期)"}
	    ];
	    if(payDepositOff){
	    	type=type.del(1);
	    }
	    var relationType = Ext.data.Store({
	    	autoDestroy: true,
	        fields :["value","text"],
	        data : type
	    });
	    
	    //员工list
	    var needRecUserList = new Ext.data.Store({
	        fields: ["userName", "id"],
	        proxy:{
	            type:'ajax',
	            url:jypath+'/customer/customer/userByProjectIdForGroup',
	            reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
	        },
	        autoLoad: false
        });
	    
	    needRecUserList.on("beforeload", function(){
			var projectId = Ext.getCmp("needRecProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
				return false;
			}
			needRecUserList.proxy.extraParams.projectId = projectId;
		})
	    
	    //房号list
	    var roomList = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["combinedName", "id"],
	        proxy:{
	            type:'ajax',
	            url:jypath+'/marketing/haveReceiveRefund/findRoomId',
	            reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
	        },
	        autoLoad:true
        });
		
		var formg = Ext.create("Ext.form.Panel", {
		    title: "查询条件",
		    collapsible: true,  //可折叠
		    autoScroll: false,   //自动创建滚动条
		    defaultType: 'textfield',
		    defaults: {
		    	 anchor: '100%'
		    },
		    fieldDefaults: {
		        margin: 2,
		        labelWidth: 80,
                labelAlign: "right",
                margin: "0 0 10 0"
		    },
		    items: [
		            { xtype: "hiddenfield", name: "docType", value: "0"},
		            {
					    xtype: "container",
					    layout: "hbox",
					    items: [
							{  
					            xtype:'combobox',
					            id:'needRecProjectStore',
					            name: "projectId",
					            store: needRecProjectStore,
					            valueField: "id",  
					            displayField: "projectName",
					            fieldLabel:'所属项目',
					            queryMode:'local',
					            typeAhead: true,
					            listeners:{
					            	'change':function(value){
					            		//加载组团数据
					            		if(value.lastValue && value.lastValue != "-1"){
					            			needRecUserList.load();
					            			needRecPremisesStore.load({
					            				callback: function(records, operation, success){
					            					//若无组团数据，加载楼栋
					            					var recordLen = records.length;
					            					if(recordLen == 0){
					            						needRecBuildingStore.load();
					            					}
					            				}
					            			});
					            		}else{
					            			needRecUserList.removeAll();
					            			needRecPremisesStore.removeAll();
					            			needRecBuildingStore.removeAll();
					            			needRecUnitStore.removeAll();
					            			needRecRoomStore.removeAll();
					            			Ext.getCmp("needRecPremisesStore").setValue("");
					            			Ext.getCmp("needRecBuildingStore").setValue("")
					            			Ext.getCmp("needRecUnitStore").setValue("")
					            			Ext.getCmp("needRecRoomStore").setValue("")
					            		}
					            	}
					            }
					        },
							{  
					            xtype:'combobox',
					            id:'needRecPremisesStore',
					            name: "premisesId",
					            store: needRecPremisesStore,
					            valueField: "id",  
					            displayField: "groupName",
					            queryMode:'local',
					            typeAhead: true,
					            listeners:{
					            	'change':function(value){
					            		//加载楼栋
					            		//若无楼栋数据，加载单元
					            		if(value.lastValue && value.lastValue != "-1"){
					            			needRecBuildingStore.load({
					            				callback: function(records, operation, success){
					            					//若无组团数据，加载楼栋
					            					var recordLen = records.length;
					            					if(recordLen == 0){
					            						needRecUnitStore.load();
					            					}
					            				}
					            			});
					            		}
					            	}
					            }
					        },
							{  
					            xtype:'combobox',
					            id:'needRecBuildingStore',
					            name: "buildingId",
					            store: needRecBuildingStore,
					            valueField: "id",  
					            displayField: "buildingName",
					            queryMode:'local',
					            typeAhead: true,
					            listeners:{
					            	'change':function(value){
					            		//加载单元
					            		//若无单元数据，加载房间
					            		if(value.lastValue && value.lastValue != "-1"){
					            			needRecUnitStore.load({
					            				callback: function(records, operation, success){
					            					//若无组团数据，加载楼栋
					            					var recordLen = records.length;
					            					if(recordLen == 0){
					            						needRecRoomStore.load();
					            					}
					            				}
					            			});
					            		}
					            	}
					            }
					        },
							{  
					            xtype:'combobox',
					            id:'needRecUnitStore',
					            name: "unitId",
					            store: needRecUnitStore,
					            valueField: "id",  
					            displayField: "unitName",
					            queryMode:'local',
					            typeAhead: true,
					            listeners:{
					            	'change':function(value){
					            		//加载房间
					            		if(value.lastValue && value.lastValue != "-1"){
					            			needRecRoomStore.load();
					            		}
					            	}
					            }
					        },
							{  
					            xtype:'combobox',
					            id:'needRecRoomStore',
					            name: "roomId",
					            store: needRecRoomStore,
					            valueField: "id",  
					            displayField: "roomName",
					            queryMode:'local',
					            typeAhead: true
					        }
			        	]
					},
		            {
		            xtype: "container",
		            layout: "hbox",
		            items: [{ 
							xtype: "checkboxgroup",
							id:"busStatusg",
							fieldLabel: "业务类型",
							name :"businessType",
							width:400,
							items:[{
						    		boxLabel:'认筹',
						    		inputValue:'0'
						    		// hidden: payDepositOff
						    	},{
						    		boxLabel:'认购',
						    		inputValue:'1'
						    	},{
						    		boxLabel:'签约',
						    		inputValue:'2'
						    	},{
						    		boxLabel:'面积补差',
						    		inputValue:'3'
						    	}
						     ]
						}
		            ]
	            },{
		            xtype: "container",
		            layout: "hbox",
		            items: [
		                {  
		                  xtype:'combobox',
		 		    	  fieldLabel:'房款类型',
		 		    	  store:relationType,
		 		    	  displayField: "text",
		 		    	  valueField:"value",
		 		    	  name:'housingFundType',
		 		    	  id:'housingFundType'
	        	        },
	        	        {  
		                  xtype:'combobox',
		 		    	  fieldLabel:'经&nbsp;&nbsp;纪&nbsp;人',
		 		    	  store:needRecUserList,
		 		    	  displayField: "userName",
		 		    	  valueField:"id",
		 		    	  name:'createUserId',
		 		    	  id:'createUserId'
	        	        }
					
		            ]
	            },{
	            	 xtype: "container",
			            layout: "hbox",
			            items: [
							{ xtype: "textfield", name: "relationCode", fieldLabel: "业务编号"},
							{ xtype: "textfield", name: "customer_name", fieldLabel: "客户名称"}
	                   ]
	            },,{
	            	 xtype: "container",
			         layout: "hbox",
			         items:[
						{
							xtype:'container',
							layout:'hbox',
							items:[{
								xtype:'datefield',
						        fieldLabel:'开始有效日期',
						        name:'ysDateStart',
						        format: 'Y-m-d'
							},{
								xtype:'datefield',
								name:'ysDateEnd',
						        format: 'Y-m-d',
						        fieldLabel:'结束有效日期'
							}]
						}
	                ]
	            }
		        ],
		    buttons: [
	  	        { xtype: "button", text: "查询", 
	  	        	handler:function(){
	  	        		//获取通过checkboxgroup定义的checkbox值
	  	        		//业务类型
	  	        		var busStatusValue = Ext.getCmp('busStatusg').getChecked();
	  	        		var busStatus="";
	  	        		Ext.Array.each(busStatusValue, function(item){
	  	        			busStatus += item.inputValue+',' ;
	  	        		});
	  	        	/*	if(busStatus != ""){
	  	        			busStatus = busStatus.substring(0, busStatus.lenght-1);
	  	        		}*/
	  	        		gridStoreg.getProxy().extraParams.businessType = busStatus;
	  	        		gridStoreg.load();
	  	        		var pagingTool=Ext.getCmp("pagingTool1");
	  	        		pagingTool.moveFirst();//跳至第一页
	  	        	}  
	  	        },{
	  	        	 xtype: "button", text: "导出",hidden:finNeedReceiveExport,handler:function(){
	  	        		var count = gridg.getStore().getCount();
	  	        		if(count<=0){
	  	        			Ext.MessageBox.alert("系统提示","没有可导出的数据");
	  	        		}else{
	  	        			var busStatusValue = Ext.getCmp('busStatusg').getChecked();
		  	        		var busStatus="";
		  	        		Ext.Array.each(busStatusValue, function(item){
		  	        			busStatus += item.inputValue+',' ;
		  	        		});
		  	        		
		  	        		gridStoreg.getProxy().extraParams.businessType = busStatus;
		  	        		var value = encodeURI(encodeURI(JSON.stringify(gridStoreg.getProxy().extraParams),"utf-8"));
		  	        		var url = jypath + "/marketing/needReceiveRefund/needReceicerefundExport?json="+value;
		  	        		location.href = url;
	  	        		}
	  	        	
	  	        	 }
	  	        },
	  	        { xtype: "button", text: "清空",handler:function(){
	  	        		formg.getForm().reset();
	  	        	}
	  	        }
	  	    ]    
	});
	
	 gridStoreg = Ext.create('Ext.data.Store', {
        fields: ["relationId", "businessType", "relationCode", "customer_name", "customerFamilyName", "combined_name", "price", "totalPrice",
                 "calculatArea", "relationType", "totalReceivablesAmount", "receivablesDate", 
                 "receivedAmount", "uncollectedAmount", "signId","id"],
        pageSize: 10,  //页容量15条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        proxy: {
            type: 'ajax',
            url: jypath+'/marketing/needReceiveRefund/list?resourcesCode=menu_0003_0001',
            actionMethods: { read: 'POST' },
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            }
        },
        autoLoad: true  //即时加载数据
    });
	
	gridStoreg.on("beforeload",function(){
        Ext.apply(gridStoreg.proxy.extraParams,formg.getForm().getValues());
        var projectId = Ext.getCmp("needRecProjectStore").getValue();
        if(projectId == "-1"){
        	gridStoreg.proxy.extraParams.projectId = "";
        }
        var newResCode = "menu_0003_0001";
        gridStoreg.proxy.extraParams.resourcesCode = newResCode;
    });
	
	var gridg = Ext.create('Ext.grid.Panel', {
		minHeight:450,
		minWidth:300,
        store: gridStoreg,
        columnLines: true,
        columns: [{  
        	text : "操作",  
            dataIndex: 'actioncolumn',
            width:300,
            locked   : true,
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
            	var rec = gridg.getStore().getAt(rowIndex);
                //收款
            	var url = "";
            	var html = "";
            	if(rec.get('businessType') == "0"){
            		//认筹
            		url = "/marketing/proceeds/deposit?id="+rec.get('relationId')+"&1=1";
            		var tabKey = "dep_pay"+rec.get('relationId');
                	html = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"收支管理\",\""+url+"\")' style='cursor:pointer'>收款</a>&nbsp;&nbsp;";
            	}else if(rec.get('businessType') == "1"){
            		//认购
            		url = "/marketing/proceeds/subscribe?id="+rec.get('relationId')+"&1=1";
            		var tabKey = "sub_pay"+rec.get('relationId');
                	html = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"收支管理\",\""+url+"\")' style='cursor:pointer'>收款</a>&nbsp;&nbsp;";
            	}else if(rec.get('businessType') == "2"){
            		//签约
            		url = "/marketing/proceeds/signed?id="+rec.get('relationId')+"&1=1";
            		var tabKey = "sig_pay"+rec.get('relationId');
                	html = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"收支管理\",\""+url+"\")' style='cursor:pointer'>收款</a>&nbsp;&nbsp;";
            	}else if(rec.get('businessType') == "3"){
            		//面积补差
            		url = "/marketing/proceeds/area?id="+rec.get('relationId')+"&1=1";
            		var tabKey = "area_pay"+rec.get('relationId');
            		html = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"收支管理\",\""+url+"\")' style='cursor:pointer'>收款</a>&nbsp;&nbsp;";
            	}
	        	//var html = '<a href="'+url+'" style="cursor:pointer">收款</a>&nbsp;&nbsp;';
	        	//延期
	        	if(!marketingDeferredPayment && rec.get('businessType') == "2"){
	        		var tabKey = "def_"+rec.get('relationId');
	        		var yiqiUrl="/router/marketing/receivables/deferredPayment?signedId="+rec.get('relationId')+"&needReceiveRefundId="+rec.get('id')+"&1=1";
//	                html += "<a href='javascript: parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"延期收款\",\""+yiqiUrl+"\")' style='cursor:pointer'>延期收款</a>"
//	        		html += "<a href='javascript: startDeferedPayment('"+tabKey+"', '"+yiqiUrl+"', '"+signedId+"');' style='cursor:pointer'>延期收款</a>";
	        		html+='<a href="javascript: startDeferedPayment(\''+tabKey+'\',\''+yiqiUrl+'\','+rec.get('relationId')+')" style="cursor:pointer">延期收款</a>';
	        	}
	        	if(!dataRepairNeedReceiveDelete){
	        		html+='&nbsp;&nbsp;<a href="javascript:needReceiveDelete('+rec.get('id')+')" style="cursor:pointer">删除</a>';
	        	}
	        	return html;
            }
        },{
            text: '业务编号',
            dataIndex: 'relation',
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
            	var rec = gridg.getStore().getAt(rowIndex);
            	var url = "";
            	if(rec.get('businessType') == "0"){
            		//认筹
            		url = jypath+"/customer/payDeposit/toView?id="+rec.get('relationId')+'&returnUrl=,marketing,needReceiveRefund,index';
            	}else if(rec.get('businessType') == "1"){
            		//认购
            		url = jypath+"/customer/subscribe/toView?id="+rec.get('relationId')+'&returnUrl=,marketing,needReceiveRefund,index';
            	}else if(rec.get('businessType') == "2"){
            		//签约
            		url = jypath+"/customer/signed/toView?id="+rec.get('relationId')+'&returnUrl=,marketing,needReceiveRefund,index';
            	}else if(rec.get('businessType') == "3"){
            		//面积补差
            		url = jypath+"/marketing/reserveArea/reserveAreaDetail?id="+rec.get('relationId');
            	}
	        	var html = '<a href="'+url+'" style="cursor:pointer">'+rec.get('relationCode')+'</a>';
	        	return html;
	        }
        },{
            text     : '客户名称', 
            dataIndex: 'customer_name'
        },{
			text     : '共同购房者',
			dataIndex: 'customerFamilyName'
		},{
            text     : '房号',
            dataIndex: 'combined_name',
            width    : 240
        },{
            text     : '签约面积(㎡)',
            dataIndex: 'calculatArea'
        },{
            text     : '签约单价(元)',
            dataIndex: 'price'
        },{
            text     : '签约金额(元)',
            dataIndex: 'totalPrice'
        },{
            text     : '房款类型',
            dataIndex: 'relationType'
        },{
            text     : '应收金额(元)',
            dataIndex: 'totalReceivablesAmount'
        },{
            text     : '应收日期',
            dataIndex: 'receivablesDate',
            renderer:function(value){
            	if(value != "" && value != null && value != "null"){
            		return Ext.Date.format(new Date(value),'Y-m-d');
            	}else{
            		return "";
            	}
            }
        },{
            text     : '已收金额(元)',
            dataIndex: 'receivedAmount'
        },{
            text     : '未收金额(元)',
            dataIndex: 'uncollectedAmount'
        }],
        title: '待收款明细列表',
        dockedItems: [{  
            xtype: 'pagingtoolbar',  
            store: gridStoreg,   // GridPanel中使用的数据  
            dock: 'bottom',  
            displayInfo: true,  
            emptyMsg:"没有数据",  
            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据",
            id:'pagingTool1'
        }
        ]
    });
	
		
		var defaultConfigg = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
				items:[formg,gridg]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
		
	}
});

function shoukuan(id){
	location.href=jypath+"/marketing/proceeds/deposit?id="+id;
}

/**
 * 删除待收款记录，此条待收款没有已收记录才可以进行删除，有则提示
 * @param id
 */
function needReceiveDelete(id){

    Ext.MessageBox.confirm("提示","是否删除该待收款记录?",function(btn,txt){
    	if(btn=="yes"){
    		Ext.Ajax.request({
    			 url: jypath+'/hoxfit/needReceiveDelete',
                 params: { id: id},
                 method: 'POST',
                 callback: function (options, success, response) {
                	 if (success) {
                		 var obj = eval('(' + response.responseText + ')');
                		 if(obj.res == '100'){
                			 Ext.MessageBox.alert("系统提示","该账号没有删除权限");
                		 }else if(obj.res == '0'){
                			 Ext.MessageBox.alert("系统提示",obj.resMsg);
                		 }else if(obj.res == '1'){
                			 Ext.MessageBox.alert("系统提示","删除待收款记录成功");
                    		 gridStoreg.load();
                		 }
                	 }else{
                		 Ext.MessageBox.alert("系统提示","删除待收款记录失败！");
                	 }
                 }
    		});
        }
    });
}

function startDeferedPayment(tabKey, yiqiUrl, signedId){
	Ext.Ajax.request({
        url: contextPath+'/customer/signed/toDeferredPaymentIS',
        params: {
     	   signedId: signedId
        },
        method: 'POST',
        success: function(response){
            var text = Ext.decode(response.responseText);
            //res: 0,失败(基本为异常) 1,成功
            //resMsg: 0(正常发起), 1(存在审核中内容,不允许发起), 2(存在通过的延期,提醒后发起)
            if(text.res=="0"){
         	   Ext.MessageBox.alert("系统提示",text.resMsg);
         	   return;
            }else if(text.res=="1"){
         	   if(text.resMsg == "1"){
         		   Ext.MessageBox.alert('提示', '已发起延期收款申请，请等待审核。您可在【待办事项-我的发起】中查看审批进度。');
         		   return;
         	   }else if(text.resMsg == "2"){
         		   var obj = text.obj;
         		   Ext.MessageBox.confirm(
     				   "系统提示",
     				   "<h5>审批过同类流程。</h5><div>" + obj + "</div><h4 style='color: red;'>是否继续申请?</h4>",
     				   function(btn){
     					   if("yes" == btn){
     						   parent.openMenu("0",tabKey,"","延期收款",yiqiUrl);
     			   			}
     				   },
					this
					);
         	   }else{
         		   parent.openMenu("0",tabKey,"","延期收款",yiqiUrl);
         	   }
	       	   }else{
	       		   parent.openMenu("0",tabKey,"","延期收款",yiqiUrl);
	       	   }
        }
	});
}
